<?php

include('wt_config.inc.php');
include('db.inc.php');

function db_titles_jq($like, $eq) {
    $sql = "SELECT `id`, `title`, `active`
        FROM `record`
        WHERE `source` $eq 'SFX'
		AND `title` LIKE '%" . mysql_real_escape_string($like) . "%'
        ORDER BY `title` ASC LIMIT 15";
    $res = safe_query($sql);
    $r = array();
    while ($row = mysql_fetch_assoc($res)) {
        if (!$row['active']
            )$row['title'].=' [disabled]';
        $r[] = array('label' => $row['title'], 'value' => $row['id']);
    }
    return json_encode($r);
}

$eq = '=';
if ($_GET['type'] == 'local') {
    $eq = '!=';
}
header("Content-type: text/javascript");

echo $_GET['callback'] . '('
 . db_titles_jq($_GET['like'], $eq)
 . ');
';

